package com.feituan.core.persistence.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.feituan.core.pojo.response.page.PageData;
import com.feituan.core.persistence.mapper.CouponMapper;
import com.feituan.core.persistence.service.ICouponService;
import com.feituan.core.pojo.entity.Coupon;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feituan.core.pojo.request.CommonPageReq;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaohu
 * @since 2024-05-09
 */
@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements ICouponService {

    @Override
    public PageData<Coupon> queryPage(CommonPageReq request) {
        Page<Coupon> page = this.lambdaQuery()
                .eq(!ObjectUtils.isEmpty(request.getName()), Coupon::getName, request.getName())
                .page(new Page<>(request.getPage(), request.getLimit()));
        return PageData.build(page.getCurrent(), page.getTotal(), page.getRecords());
    }

    @Override
    public Coupon selectById(Long id) {
        return this.baseMapper.selectById(id);
    }
}
